<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="信息标题" prop="infoTitle">
        <el-input
          v-model="queryParams.infoTitle"
          placeholder="请输入供求信息标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <el-form-item label="信息内容" prop="infoTitle">
        <el-input
          v-model="queryParams.infoContent"
          placeholder="请输入供求信息内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>




      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col> -->
    </el-row>

    <el-table v-loading="loading" :data="infosList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="供求信息编号" align="center" prop="infoId" />
      <el-table-column label="供求信息标题" align="center" prop="infoTitle" />
  
      <el-table-column label="供求信息种类" align="center" prop="typeName" />
   
      <el-table-column label="用户" align="center" prop="users.userName" />
      <el-table-column label="手机" align="center" prop="users.userPhone" />
      <el-table-column label="状态" align="center" prop="infoState"  >
         <template slot-scope="scope" >
            <div style="color:#F56C6C">
            <span v-if="scope.row.infoState=== 0" >审核中</span>
            <span v-if="scope.row.infoState=== 1">未通过</span>
            <span v-if="scope.row.infoState=== 2" >发布中</span>
            <span v-if="scope.row.infoState=== 3">已完成</span>
            </div>
         </template>
      </el-table-column>



      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>
<div align=center style="margin-top:20px">
<el-pagination
text-align:center
  background
  layout="prev, pager, next"
  :total=total
  :page-size=queryParams.pageSize
  :current-page=this.queryParams.pageNum
  @current-change="handleCurrentChange"
    >
</el-pagination>
</div>

    <!-- 添加或修改供求信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px"   append-to-body >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" >

      <el-row>
        <el-col :span="12">
        <el-form-item label="供求信息标题" prop="infoTitle" >
          <el-input v-model="form.infoTitle" placeholder="请输入供求信息标题" disabled/>
        </el-form-item>
          </el-col>
         <el-col :span="12">
          <el-form-item  label="信息类型" prop="categoryName" >
          <el-select v-model="form.categoryName"  placeholder="请选择" disabled>
              <el-option
                v-for="item in categorys"
                :key="item.categoryId"
                :label="item.categoryName"
                :value="item.categoryId">
              </el-option>
            </el-select>
        </el-form-item>
           </el-col>              
      </el-row>
      
      <el-row>
        <el-col :span="12">
        <el-form-item label="供求信息内容" >
          <el-input v-model="form.infoContent" placeholder="请输入供求信息内容" disabled/>
        </el-form-item>
        </el-col>
         <el-col :span="12">
     <el-form-item  label="信息种类" prop="typeName" >
             <el-select v-model="form.typeName"  placeholder="请选择" disabled>
              <el-option
                v-for="item in types"
                :key="item.typeId"
                :label="item.typeName"
                :value="item.typeId">
              </el-option>
            </el-select>
        </el-form-item>
               </el-col>              
      </el-row>
         <el-row>
            <el-col :span="12">
        <el-form-item label="供求信息价格" prop="infoPrice">
          <el-input v-model="form.infoPrice" placeholder="请输入供求信息价格" disabled/>
        </el-form-item>
               <el-form-item label="地址" prop="infoAddress">
          <el-input v-model="form.infoAddress" placeholder="请输入地址" disabled/>
        </el-form-item>
               </el-col>  
            <el-col :span="12">    
       <el-form-item label="图片" prop="infoPostscript">
          <div class="demo-image__preview">
               <image-preview :src="form.infoImg" :width="100" :height="100" />
          </div>
        </el-form-item>
         </el-col>       
       
      </el-row>
  
          <el-row>
            <el-col :span="12">            
          <el-form-item label="姓名" prop="infoPostscript">
          <el-input v-model="form.users.userName" placeholder="" disabled/>
        </el-form-item>
          <el-form-item label="电话" prop="users.userPhone">
          <el-input v-model="this.form.users.userPhone" placeholder="" disabled/>
        </el-form-item>
            </el-col>
                <el-col :span="12">
               <el-form-item label="邮箱" prop="users.userEmail">
          <el-input v-model="this.form.users.userEmail" placeholder="" disabled/>
        </el-form-item>    
           
      </el-col>
          </el-row>
 
        
        <el-form-item label="反馈" prop="infoPostscript">
          <el-input  type="textarea" v-model="form.infoPostscript" placeholder="请输入反馈信息"   class="bgcolor: red;"  />
        </el-form-item>
          
      </el-form>
      <div slot="footer" class="dialog-footer " style="ma">
        <el-button type="primary" @click="submitSuccess">重新审核</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { verifyInfos, getInfos, delInfos, updateInfotate} from "@/api/infos";
import { listCategorysAll } from "@/api/categorys";
import { listTypeAlls } from "@/api/types";
import axios from 'axios';
export default {
  name: "Infos",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供求信息表格数据
      infosList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        infoTitle: null,
        infoContent: null,
        infoAddress: null,
        infoImg: null,
        infoPostscript: null,
        infoState: 1,
        infoDelete: null
      },
      // 表单参数
      form: {users:{}},
      // 表单校验
      rules: {
      },
        fileList: [],
        //状态选择
       options: [{
          value: 0,
          label: '审核中'
        }, {
          value: 1,
          label: '未通过'
        }, {
          value: 2,
          label: '发布中'
        }, {
          value: 3,
          label: '已完成'
        }
        ],
       //分类集合
      categorys:[],
      //种类集合
      types:[],
      //用户信息
    //  users:null,
      
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询供求信息列表 */
    getList() {
      this.loading = true;
      verifyInfos(this.queryParams).then(response => {
     
        this.infosList = response.content.data.list;
           console.log( this.infosList)
        // this.users= response.content.data.list.users;
        this.total = response.content.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        infoId: null,
        infoTitle: null,
        infoContent: null,
        infoPrice: null,
        infoAddress: null,
        infoImg: null,
        infoPostscript: null,
        infoState: null,
        infoCreatetime: null,
        infoUpdatetime: null,
        infoDelete: null,
        typeName:null,
        categoryName:null,
        typeInfoId:null,
       users:{}
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
          //初始化表单
    resetForm(formName) {
    //  this.queryParams.adminName=null;
    //  this.queryParams.adminAccount=null;
    //  this.queryParams.adminPhone=null;
    //   this.$nextTick(() => {
        this.$refs[formName].resetFields();
    //   });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.infoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
        listCategorysAll().then(res=>{
     this.categorys= res.content.data;
    })
      listTypeAlls(null).then(res=>{
     this.types= res.content.data;
    })
      this.title = "添加供求信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const infoId = row.infoId || this.ids
      getInfos(infoId).then(response => {
        this.form =  response.content.data;
           console.log( this.form)
        this.open = true;
        this.title = "修改供求信息";
      });
    },
    /** 提交按钮 审核通过*/
    submitSuccess() {
      this.form.infoState=0
      updateInfotate(this.form).then(res=>{
        this.$modal.msgSuccess("重新审核"); 
      this.open = false;
       this.getList();
      })
      // this.$router.go(0)
     
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const infoIds = row.infoId || this.ids;
      this.$modal.confirm('是否确认删除供求信息编号为"' + infoIds + '"的数据项？').then(function() {
        return delInfos(infoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
 
           //改变页码      
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.getList()
    },
  }
};
</script>
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

   .bottoncss {
    top: 10030px;
  }


</style>